<template>
  <div class="notice-detail-container">
    <div class="notice-content" v-if="!loading">
      <div class="notice-detail-title">
        <span>{{ title }}</span>
      </div>
      <div class="notice-detail-description">
        <span>发表人： {{ author }}</span><br>
        <span>时间： {{ created_at }}</span>
      </div>
      <div class="notice-detail-content" v-html="content"></div>
      <div class="notice-detail-backBtn" @click="back">
        <a-icon class="backBtn-icon" type="left-square"/>
      </div>
    </div>

    <!--加载框-->
    <a-spin class="loading" tip="Loading..." spinning v-if="loading"/>
  </div>
</template>

<script>
export default {
  name: 'NoticeDetail',
  created () {
    this.noticeId = this.$route.query.noticeId
    this.noticeDetail()
  },
  data () {
    return {
      loading: true,
      noticeId: 0,
      title: '',
      author: '',
      created_at: '',
      content: ''
    }
  },
  methods: {
    noticeDetail () {
      this.loading = true
      this.$http.get('/news/' + this.noticeId).then(res => {
        this.title = res.data.data.title
        this.author = res.data.data.author
        this.created_at = res.data.data.created_at
        this.content = res.data.data.content
        this.loading = false
      })
    },
    back () {
      this.$router.go(-1)
    }
  }
}
</script>

<style scoped lang="less">
.notice-detail-container {
  width: 100%;
  height: 100%;
  overflow-y: scroll;
  position: relative;
}

.notice-content {
  width: 100%;
  height: 100%;
}

.notice-detail-title {
  text-align: center;
  font-size: 40px;
  font-weight: bold;
  padding: 20px 10%;
}

.notice-detail-description {
  text-align: center;
  font-size: 14px;
  padding: 0 10%;
}

.notice-detail-content {
  padding: 20px 5%;
}

.notice-detail-backBtn {
  position: absolute;
  left: 5%;
  top: 100px;
  width: 40px;
  height: 40px;
  background-color: black;
  opacity: 0.4;
  border-radius: 5px;
  cursor: pointer;
  transition: 0.2s;
  display: flex;
  justify-content: center;
  align-items: center;
}

.notice-detail-backBtn:hover {
  opacity: 0.6;
}

.backBtn-icon {
  font-size: 25px;
  color: white
}

.loading {
  position: absolute;
  width: 100px;
  height: 100px;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
</style>
